home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today (Latin America) Volume 1 #6 / CD-ROM Today 6 Latam.iso / referenc / evol / database.dxr / 00098_BinChop.ls < prev    next >
Encoding:
Text File  |  1996-11-08  |  794 b   |  34 lines

  1. on BinarySearch artName
  2.   global gArtLib
  3.   set ArtStart to 1
  4.   set ArtEnd to 306
  5.   set ArtLib to gArtLib
  6.   set bFound to 0
  7.   set bMissing to 0
  8.   set chkCount to 0
  9.   repeat while not bFound and not bMissing
  10.     set midPt to (ArtStart + ArtEnd) / 2
  11.     put midPt & "..."
  12.     set chkMem to the name of member midPt of castLib ArtLib
  13.     set bFound to artName = chkMem
  14.     put artName & "=" & chkMem & " is " & bFound
  15.     set chkCount to chkCount + 1
  16.     if not bFound then
  17.       if ArtStart >= ArtEnd then
  18.         set bMissing to 1
  19.       end if
  20.       if artName < chkMem then
  21.         set ArtEnd to midPt - 1
  22.         next repeat
  23.       end if
  24.       set ArtStart to midPt + 1
  25.     end if
  26.   end repeat
  27.   if bMissing then
  28.     return 0
  29.   else
  30.     put "returnval = " & midPt
  31.     return midPt
  32.   end if
  33. end
  34.